/**
 * 态势对象数据管理 API
 */
import { apiAdminGet, apiAdminPost, apiAdminPut, apiAdminDelete, apiGet } from './base'

/**
 * 获取态势对象列表
 * @param {Object} params - 查询参数
 * @param {number} params.page - 页码
 * @param {number} params.page_size - 每页数量
 * @param {string} params.object_type - 对象类型筛选
 * @param {string} params.equipment_category - 装备类别筛选
 * @param {string} params.deployment_status - 部署状态筛选
 * @param {string} params.organization - 所属单位筛选
 * @param {string} params.search - 搜索关键字
 * @returns {Promise}
 */
export function getSituationObjects(params = {}) {
  const queryParams = new URLSearchParams()

  if (params.page) queryParams.append('page', params.page)
  if (params.page_size) queryParams.append('page_size', params.page_size)
  if (params.object_type) queryParams.append('object_type', params.object_type)
  if (params.equipment_category) queryParams.append('equipment_category', params.equipment_category)
  if (params.deployment_status) queryParams.append('deployment_status', params.deployment_status)
  if (params.organization) queryParams.append('organization', params.organization)
  if (params.search) queryParams.append('search', params.search)

  return apiGet(`/api/situation/objects?${queryParams.toString()}`)
}

/**
 * 获取单个态势对象详情
 * @param {string} objectId - 对象ID
 * @returns {Promise}
 */
export function getSituationObject(objectId) {
  return apiGet(`/api/situation/objects/${objectId}`)
}

/**
 * 创建态势对象
 * @param {Object} data - 对象数据
 * @returns {Promise}
 */
export function createSituationObject(data) {
  return apiAdminPost(`/api/situation/objects`, data)
}

/**
 * 更新态势对象
 * @param {string} objectId - 对象ID
 * @param {Object} data - 更新数据
 * @returns {Promise}
 */
export function updateSituationObject(objectId, data) {
  return apiAdminPut(`/api/situation/objects/${objectId}`, data)
}

/**
 * 删除态势对象
 * @param {string} objectId - 对象ID
 * @returns {Promise}
 */
export function deleteSituationObject(objectId) {
  return apiAdminDelete(`/api/situation/objects/${objectId}`)
}

/**
 * 批量删除态势对象
 * @param {Array<string>} objectIds - 对象ID数组
 * @returns {Promise}
 */
export function batchDeleteSituationObjects(objectIds) {
  return apiAdminPost(`/api/situation/objects/batch-delete`, objectIds)
}

/**
 * 获取统计信息
 * @returns {Promise}
 */
export function getSituationStatistics() {
  return apiGet(`/api/situation/statistics`)
}

/**
 * 批量导入数据
 * @param {string} format - 文件格式 (json/csv/xml/yaml)
 * @param {string} data - 文件内容
 * @returns {Promise}
 */
export function importSituationData(format, data) {
  return apiAdminPost(`/api/situation/import`, { format, data })
}

/**
 * 批量导出数据
 * @param {string} format - 导出格式 (json/csv/xml/yaml)
 * @param {string} objectType - 对象类型筛选（可选）
 * @returns {Promise}
 */
export function exportSituationData(format = 'json', objectType = null) {
  const queryParams = new URLSearchParams()
  queryParams.append('format', format)
  if (objectType) queryParams.append('object_type', objectType)

  return apiAdminGet(`/api/situation/export?${queryParams.toString()}`)
}

/**
 * 获取支持的对象类型列表
 * @returns {Promise}
 */
export function getSituationTypes() {
  return apiGet(`/api/situation/types`)
}

/**
 * 获取部署状态列表
 * @returns {Promise}
 */
export function getDeploymentStatuses() {
  return apiGet(`/api/situation/deployment-statuses`)
}

/**
 * 获取装备类别列表
 * @param {string} objectType - 对象类型筛选（可选）
 * @returns {Promise}
 */
export function getEquipmentCategories(objectType = null) {
  const queryParams = new URLSearchParams()
  if (objectType) queryParams.append('object_type', objectType)

  return apiGet(`/api/situation/equipment-categories?${queryParams.toString()}`)
}

export function getEquipmentCategoryLabels() {
  return apiGet('/api/situation/equipment-category-labels')
}

/**
 * 获取关系类型列表
 * @returns {Promise}
 */
export function getRelationshipTypes() {
  return apiGet('/api/situation/relationship-types')
}
